import java.util.*;

public class Main {

    public static int n;
    public static String[] strs;
//    public static int[] count; //对应的字符串最多被使用的次数
    public static char start;
    public static List<String> list = new ArrayList<>();

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        n = sc.nextInt();
        strs = new String[n];
        for (int i = 0; i < n; i++) {
            strs[i] = sc.next();
        }
        start = sc.next().charAt(0); //开始字符


        //找到以 start 开始的字符串
        for (int i = 0; i < n; i++) {
            if (strs[i].charAt(0) == start) {
                //对应字符串的剩余使用次数
                int[] count = new int[n];
                for (int j = 0; j < n; j++) {
                    count[j] = 2;
                }
                count[i]--;
                dfs(strs[i], count);
            }
        }

        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.length() - o1.length();
            }
        });

        System.out.println(list.get(0).length());

        sc.close();
    }

    /**
     * 已经拼接的字符串
     * @param str
     */
    public static void dfs(String str, int[] count) {

        //判断递归结束，遍历 strs，查看是否有字符串与 str 匹配的
        boolean flag = false;
        for (int i = 0; i < n; i++) {
            if (count[i] > 0) {
                if (isMatch(str, strs[i]) != -1) { //有匹配的
                    flag = true;
                    break;
                }
            }
        }

        if (!flag) {
            list.add(str);
            return;
        }

        int lenStr = str.length();

        for (int i = 0; i < n; i++) {
            if (count[i] > 0) {
                int index = isMatch(str, strs[i]);
                if (index != -1) {
                    int len = strs[i].length();
                    count[i]--;
                    dfs(str + strs[i].substring(index + 1, len), count);

                    //回溯
                    count[i]++;
                }
            }
        }
    }

    /**
     * 判断 str1 的结尾若干字符与 str2 的开始若干字符是否匹配
     * @param str1
     * @param str2
     * @return 返回 str2 开始重合的下标，从 0 开始，没有重合的部分就返回 -1
     */
    public static int isMatch(String str1, String str2) {
        int len1 = str1.length();
        int len2 = str2.length();

        if (str2.startsWith(str1) || str1.endsWith(str2)) {
            return -1;
        }

        for (int i = 0; i < len2; i++) {
            String startStr = str2.substring(0, i + 1);
            if (str1.endsWith(startStr)) {
                return i;
            }
        }

        return -1;
    }
}
